#include <iostream>
#include <vector>
using namespace std;

class Solution
{
public:
    long long sumDigitDifferences(vector<int> &nums)
    {
        // bit @3 has n count of @1 n=dic[3][1]
        std::vector<std::vector<long>> dic;
        dic.resize(9);
        for (size_t i = 0; i < 9; i++)
        {
            //[0-9]for number,10 for sum
            dic[i].resize(11, 0);
        }
        long long ans = 0;
        for (auto number : nums)
        {
            for (int j = 0; j < 9; j++)
            {
                int bit = number % 10;
                ans += dic[j][10] - dic[j][bit];
                dic[j][bit]++;
                dic[j][10]++;
                number = number / 10;
            }
        }
        return ans;
    }
};

int main()
{
    cout << "Code3153" << endl;
    Solution s;
    // std::vector<int> nums{13, 23, 12};
    // std::vector<int> nums{10, 10};
    std::vector<int> nums{566283079, 254111139};
    cout << s.sumDigitDifferences(nums) << endl;
    cout << "" << endl;
    return 0;
}